#include <bits/stdc++.h>
// 2025/07/20
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, v[2005], dp[2005][2005];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    for (int i = 1; i <= n; i++)
        for (int l = 0; l <= i; l++)
            dp[i][l] = max(dp[i - 1][l - 1] + v[l] * i, dp[i - 1][l] + v[n - i + l + 1] * i);
    int ans = 0;
    for (int i = 0; i <= n; i++)
        ans = max(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}